#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

struct ListNode
{
	int val;
	struct ListNode* next;
};

struct ListNode* removeElements(struct ListNode* head, int val)
{
    if (head == NULL)
    {
        return head;
    }
    struct ListNode* plist = head;
    struct ListNode* cur = head->next;
    while (cur != NULL)
    {
        if (cur->val != val)
        {
            plist = plist->next;
            plist->val = cur->val;
        }
        cur = cur->next;
    }
    if (plist == head)
    {
        head = NULL;
        return head;
    }
    plist->next = NULL;
    return head;
}

int main()
{
    //struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
    //struct ListNode* n2 = (struct ListNode*)malloc(sizeof(struct ListNode));
    //struct ListNode* n3 = (struct ListNode*)malloc(sizeof(struct ListNode));
    //struct ListNode* n4 = (struct ListNode*)malloc(sizeof(struct ListNode));

    //n1->val = 7;
    //n2->val = 7;
    //n3->val = 7;
    //n4->val = 7;
    //n1->next = n2;
    //n2->next = n3;
    //n3->next = n4;
    //n4->next = NULL;

    struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
    n1->val = 1;
    n1->next = NULL;


    struct ListNode* head = removeElements(n1, 2);

	return 0;
}